<template>
  <div class="m-container">
    <nav-header></nav-header>
    <div class="app-container m-refund-index">
      <!-- 退款退货选择页 -->
      <div class="m-goods-info clearfix">
        <div class="m-goods-img fl">
          <img v-lazy="goodsInfo.goodsMainphotoPath">
        </div>
        <div class="info">
          <p>{{goodsInfo.goodName}} {{goodsInfo.goodsSerial}}</p>
          <div v-if="goodsInfo.goodsSpecContent">
            <span>颜色：{{goodsInfo.goodsSpecContent[0]}}</span>
            <span>尺码：{{goodsInfo.goodsSpecContent[1]}}</span>
          </div>
        </div>
      </div>
      <div class="m-options">
        <p>请选择服务类型</p>
        <div class="item clearfix" @click="jumpPage('pay')">
          <div class="fl icon">
            <img src="../my/assets/refund_pay.png" alt="">
          </div>
          <div class="icon-info">
            <p>仅退款</p>
            <span>未收到货(包含未签收)，或卖家协商同意前提下</span>
          </div>
        </div>
        <div class="item clearfix" @click="jumpPage('pg')" v-if="!disabled">
          <div class="fl icon">
            <img src="../my/assets/refund_good.png" alt="">
          </div>
          <div class="icon-info">
            <p>退货退款</p>
            <span>已收到货，需要退换已收到的货物</span>
          </div>
        </div>
        <div class="item clearfix" @click="jumpPage('goods')" v-if="!disabled">
          <div class="fl icon">
            <img src="../my/assets/refund_goods.png" alt="">
          </div>
          <div class="icon-info">
            <p>换货</p>
            <span>商品存在质量问题，联系卖家协商换货</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import header from './components/header'
import { apiRefundOrderInfo } from 'js/api'
import { mapGetters } from 'vuex'

export default {
  data() {
    return {
      goodsInfo: {},
      disabled: true
    }
  },
  created() {
    if (!this.$route.params.orderid || !this.$route.params.carid) return
    apiRefundOrderInfo(this.token, this.$route.params.orderid, this.$route.params.carid).then(data => {
      this.goodsInfo = JSON.parse(data.goodsInfo || '{}')
      // 判断当前可选择的退款类型
      if (!this.goodsInfo.delivery || !this.goodsInfo.delivery.length) {
        this.disabled = false
      }
      if (this.goodsInfo.refundType) {
        this.$router.push(`/orderDetail?id=${this.$route.params.orderid}&redirect=/orderDetail?id=${this.$route.params.orderid}`)
      }
    })
  },
  methods: {
    /**
     * 根据选择类型，跳转页面
     */
    jumpPage(type) {
      if (type != 'goods') {
        this.$router.push(`/repay/${type}?id=${this.$route.params.orderid}&carid=${this.$route.params.carid}`)
        return
      }
      this.$router.push(`/regoods?id=${this.$route.params.orderid}&carid=${this.$route.params.carid}`)
    }
  },
  computed: {
    ...mapGetters(['token'])
  },
  components: {
    'nav-header': header
  }
}
</script>

<style lang="scss">
.m-container {
  .app-container {
    width: 990px;
    min-width: 990px;
  }
}
</style>

<style lang="scss" scoped>
.m-container {
  background-color: #ffffff;
  padding-bottom: 20px
}
.m-refund-index {
  margin: 20px auto;
  border: 1px solid #DDDDDD;
  padding: 0 20px;
}
.m-goods-info {
  border-bottom: 1px solid #dddddd;
  padding: 20px 10px;
  .m-goods-img {
    width: 92px;
    height: 92px;
    margin-right: 10px;
  }
  .info {
    span {
      color: #606060;
      line-height: 28px;
      padding-right: 20px;
    }
  }
}
.m-options {
  min-height: 300px;
  padding: 20px 10px;
  & > p {
    margin-bottom: 20px;
  }
  .item {
    width: 450px;
    height: 120px;
    cursor: pointer;
    display: inline-block;
    border: 1px solid #dddddd;
    padding: 36px 0 36px 36px;
    margin: 0 24px 20px 0;
    &:nth-child(2n+1) {
      margin-right: 0
    }
    .icon {
      width: 54px;
      height: 54px;
      margin-right: 12px;
      img {
        width: auto;
        height: auto;
      }
    }
    .icon-info {
      p {
        font-size: 18px
      }
      span {
        font-size: 16px;
        color: #9D9D9D;
        line-height: 32px;
      }
    }
  }
}
</style>
